cssjshtml js yyMMdd格式字符串与时间互转

葫芦的运维日志

下一篇 搜索 上一篇

浏览量 3873

2019/03/05 16:25


1.'20190222' -> Fri Feb 22 2019 00:00:00 GMT+0800 (中国标准时间),并加一天。

先在字符串中加入'/',通过new Date转换,转换后为Date对象可以做时间上的加减。

let date = new Date(event.name.slice(0, 4) + '/' + event.name.slice(4, 6) + '/' +event.name.slice(6, 8))
let starttime = date
let endtime = new Date(date.getTime() + 24 * 60 * 60 * 1000)

2.Fri Feb 22 2019 00:00:00 GMT+0800 (中国标准时间) -> '2019-02-22 00:00:00'

将Date对象转换为需要的字符串格式。

this.starttime = this.timevalue[0].getFullYear() + '-' + (this.timevalue[0].getMonth() + 1) + '-' + this.timevalue[0].getDate() + ' ' + this.timevalue[0].getHours() + ':' +this.timevalue[0].getMinutes() + ':' + this.timevalue[0].getSeconds(),
this.endtime = this.timevalue[1].getFullYear() + '-' + (this.timevalue[1].getMonth() + 1) + '-' + this.timevalue[1].getDate() + ' ' + this.timevalue[1].getHours() + ':' +this.timevalue[1].getMinutes() + ':' + this.timevalue[1].getSeconds()

 

葫芦的运维日志

打赏

上一篇 搜索 下一篇
© 冰糖葫芦甜(bthlt.com) 2021 王梓打赏联系方式 陕ICP备17005322号-1